<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="com.javapig.util.*,java.util.*"%>
<%@ page import="com.dd.XiaLaLiebiaoInfos" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>

<%@ include file="global.jsp" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%
	// overall error variable
	boolean errors = false;
	int tianjiaLeibie = ParamUtils.getIntParameter(request, "type", -1);
	if(tianjiaLeibie == -1)
	{
		tianjiaLeibie = ParamUtils.getIntParameter(request, "leibie", -1);
	}
	String[] strtianjiaTypes = { "常用意见", "常用单位", "项目类别" ,"项目事业部"};
	
	XiaLaLiebiaoInfos newInfo = new XiaLaLiebiaoInfos();

	String submit = ParamUtils.getParameter(request, "submit");
	//if (submit != null && submit.equals("提交")) 
	//{
		boolean doCreate = ParamUtils.getBooleanParameter(request,
		"doCreate");
		String content = ParamUtils.getParameter(request, "yijian");
		  // check for errors
		if( doCreate ) {

			if( content == null || content.length() <= 0) {
				errors = true;
			}
		}
		if( !errors && content != null  ) 
		{
			
			if(tianjiaLeibie == 0)
			{
				newInfo.AddYiJian(content);
			}
			else if(tianjiaLeibie == 1)
			{
				newInfo.AddDanWei(content);
			}
			else if(tianjiaLeibie == 2)
			{
				newInfo.AddLeiBie(content);
			}
			else if(tianjiaLeibie == 3)
			{
				XiangMuShiYeBuManager.InsertNewXiangMuShiYeBu(content);
			}
		}	
		
		String strdeleteid = ParamUtils.getParameter(request, "delete");
		if(strdeleteid != null)
		{
			
			if(tianjiaLeibie == 0)
			{
				newInfo.DeleteYiJian(strdeleteid);
			}
			else if(tianjiaLeibie == 1)
			{
				newInfo.DeleteDanWei(strdeleteid);
			}
			else if(tianjiaLeibie == 2)
			{
				newInfo.DeleteLeiBie(strdeleteid);
			}
		}

	//}
	
		Map historyList = null;
		switch(tianjiaLeibie)
		{
		case 0:
			historyList = newInfo.GetAllYiJian();
			break;
		case 1:
			historyList = newInfo.GetAllDanWei();
			break;
		case 2:
			historyList = newInfo.GetAllLeiBie();
			break;
		case 3:
			historyList = XiangMuShiYeBuManager.GetAllXiangMuShiYeBuInfosMap();
		}
%>


<%@ include file="header.jsp" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<p>

<%
    String[] str_TypeName = {"添加常用意见", "添加常用单位", "添加项目类别","添加项目事业部"};
    String[] str_Remark = {"添加常用意见的备注","添加常用单位的备注", "添加项目类别的备注"};
    String title = str_TypeName[tianjiaLeibie];
    String[][] breadcrumbs = {
        {"主页面", "main.jsp"},
        {title, "createUser.jsp"}
    };
    StringBuffer pageGuide = new StringBuffer();
    for (int i=0; i<breadcrumbs.length; i++){
      for(int j=0; j<breadcrumbs[i].length; j++){
          pageGuide.append(breadcrumbs[i][j]+"@");
      }
    }

%>

<jsp:include page="title.jsp" flush="true">
   <jsp:param name="title" value="<%=title%>" />
   <jsp:param name="pageGuide" value="<%=pageGuide%>" />
</jsp:include>


<font size="-1">
<form action="addOthers.jsp?type=<%=tianjiaLeibie%>" method="post">
<input type="hidden" ame="doCreate" value="true" /> 
<input type="hidden" ame ="leibie" value="<%=tianjiaLeibie%>" />
	<%
 String strLeiBie = strtianjiaTypes[tianjiaLeibie];
 %>
请输入新的<%=strLeiBie%>: <input type="text" name="yijian"> <input
	type="submit" value="提交"></form>

</font>

<table width="80%" border="0" cellpadding="2" cellspacing="1"
	 bgcolor="<%= tblBorderColor %>" rules="all" id="DataGrid1">
	<tr align="center" bgcolor="<%=tr_bakgroundColor%>">
		<td width="10%" height="30">编号</td>
		<td width="66%">内容</td>
		<%
			if(tianjiaLeibie != 3)
			{
		%>
		<td width="12%" onclick="return   confirm('您真的要删除此行吗？');">删除</td>
		<%
			}
		%>
	</tr>
	<% 	
	Set s = historyList.keySet();
	Iterator it = s.iterator();
	int xIndex = 0;
	while (it.hasNext())
	{
		String key = (String) it.next();
		xIndex++;
		if (key != null)
		{
			String val = (String) historyList.get(key);
	%>
			
		<tr bgcolor="#ffffff">
		<td height="25"><%=xIndex %></td>
		<td><%=val %></td>
		<%
			if(tianjiaLeibie != 3)
			{
		%>
		<td align="center" onclick="return   confirm('您真的要删除此行吗？');"><a href="addOthers.jsp?type=<%=tianjiaLeibie%>&delete=<%=key %>"><img src="images/button_delete.gif" width="17" height="17" alt="删除..." border="0" /></a></td>
	   </tr>	
	   <%
			}
		%>	
	<%		
		}
	}
	%>
</table>
</td>
</tr>
</table>
</body>
</html>
